In H.264 as an international coding standard, the upper limit amount of code for one macroblock is determined (see, for example, Non-Patent Document 1).
Therefore, a video encoding apparatus based on H.264 should perform encoding in a manner such that the amount of generated code generated for one macroblock does not exceed the above upper limit amount.
In order to implement the above condition, the amount of generated code is measured after encoding, and if the measured amount exceeds the upper limit, encoding should be again performed with revised encoding conditions.
However, in such a method, the amount of computation or the processing time increases due to re-encoding with revised encoding conditions.
In a proposed method for solving the above problem, encoding processes (orthogonal transformation, quantization, information source encoding, and the like) corresponding to two or more encoding modes to which different encoding conditions are assigned are simultaneously executed, and one which produces an encoding result whose amount of generated code does not exceed the relevant upper limit is selected.
However, in such a method, encoding processes corresponding to two or more encoding modes having different encoding conditions should be simultaneously executed, and an encoding result whose amount of generated code does not exceed the upper limit is not always obtained.
Therefore, in order to reliably encode each macroblock of any input image with a number of bits less than an upper limit, H.264 employs a pulse code modulation (PCM) mode in which the pixel value is directly transmitted without compression (i.e., without quantization).
In a conventional technique using the above, as shown in FIG. 18, encoding is executed after determining the encoding mode, and the amount of code generated in the encoding is measured. If the measured value exceeds an upper limit, re-encoding is performed in the PCM mode.
On the other hand, in comparison with a conventional encoding method using a coding table, an arithmetic coding method employed in H.264 has a feature such that the amount of code cannot be instantaneously measured.
Therefore, an excess over the upper limit number of bits may be detected after the processing of the next macroblock is started. In such a situation, a problem occurs in that there is a delay in a pipeline operation (i.e., parallel execution).
Accordingly, in a hardware device for performing a pipeline operation for macroblocks (as units), if an input image of a macroblock whose number of bits exceeds an upper limit is re-encoded in the above-described PCM mode, an additional memory is necessary for storing the input image until the encoding reaches the final stage.
Therefore, in a currently-proposed technique (see, for example, Non-Patent Document 2) relating to hardware devices for performing pipeline operation for macroblocks as units, when there is a macroblock whose number of bits exceeds an upper limit, not the input image of the macroblock but a local decoded image thereof in the relevant encoder is re-encoded in the PCM mode.    Non-Patent Document 1: ITU-T Rec.H.264, “Advanced video coding for generic audio visual services”, pp. 249-256, 2003.    Non-Patent Document 2: Keiichi Chono, Yuzo Senda, Yoshihiro Miyamoto, “A PCM coding method using decoded images for obeying the upper limit on the number of bits of MB in H.264 encoding”, pp. 119-120, PCSJ2006.